<?php
/**
 * Description of user
 *
 * @author Henson
 */
class Comment extends Base{
	
	private $commentTable = "tbl_comment";
	
	private $eventTable = "tbl_event";
	
	public function insertComment($insertArr)
	{
		$insertArr['uid'] = 
		$insertArr['insert_time'] = time();
		$insertArr['del'] = '0';
		return $this->db->insert($insertArr, $this->commentTable);
	}
	
	public function getCommentList($p)
	{
		$limit = " limit ".($p -1 ) * $this->pageRow .",".$this->pageRow;
		$sql = "select c.*,e.title from {$this->commentTable} c 
			left join {$this->eventTable} e on c.eid=e.id
			where c.del='0' order by c.insert_time desc, c.id desc {$limit}";
		$this->db->setQuery($sql);
		return $this->db->loadAssocList();
	}
	
	public function fGetCommentList($where, $orderby, $limit)
	{
		$sql = "select * from {$this->commentTable} {$where} {$orderby} {$limit}";
		$this->db->setQuery($sql);
		return $this->db->loadAssocList();
	}
	
	public function dealComment($commentRow)
	{
		$commentRow['addtime'] = date("Y-m-d H:i", $commentRow['insert_time']);
		$commentRow['content'] = nl2br($commentRow['content']);
		return $commentRow;
	}
	
	public function getCommentTotal()
	{
		$where = "where del='0'";
		return $this->getTotalNum($this->commentTable, $where);
	}
	
	public function getCommentTotalByEid($eid)
	{
		$where = "where del='0' and eid=".$eid;
		return $this->getTotalNum($this->commentTable, $where);
	}
}
?>